import service from '../../service'
const state = {
  count: 0,
  userName: '',
  banner: []
}

const actions = {
  increase (context, a) {
    context.commit('HOME_INCREASE')
  },
  getUserName (context) {
    service.get('/v1/getUser')
      .then((res) => {
        context.commit('HOME_GETUSERNAME', res.userName)
      })
  },
  getBanner (context) {
    service.get('/v1/home/banner')
      .then((res) => {
        context.commit('HOME_GETBANNER', res)
      })
  }
}

const mutations = {
  HOME_INCREASE: (state) => {
    state.count++
  },
  HOME_GETUSERNAME: (state, userName) => {
    state.userName = userName
  },
  HOME_GETBANNER: (state, banner) => {
    state.banner = banner
  }
}

export default {
  state,
  actions,
  mutations
}